package com.hr.domain.po;

import java.time.LocalDateTime;
import java.util.Date;
import lombok.Data;

/**
 * 用户登录日志表
 * @TableName user_login_log
 */
@Data
public class UserLoginLog {
    /**
     * 主键
     */
    private Long id;

    /**
     * 用户ID，关联 user 表
     */
    private Long userId;

    /**
     * 登录令牌（JWT 或 Session Token）
     */
    private String token;

    /**
     * 登录时间
     */
    private LocalDateTime loginTime;

    /**
     * token 过期时间
     */
    private LocalDateTime expiresAt;

    /**
     * 登出时间，用户主动退出时记录，可为空
     */
    private LocalDateTime logoutTime;

    /**
     * 登录来源：1=客户端，2=后台管理端
     */
    private Integer loginSource;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        UserLoginLog other = (UserLoginLog) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
            && (this.getToken() == null ? other.getToken() == null : this.getToken().equals(other.getToken()))
            && (this.getLoginTime() == null ? other.getLoginTime() == null : this.getLoginTime().equals(other.getLoginTime()))
            && (this.getExpiresAt() == null ? other.getExpiresAt() == null : this.getExpiresAt().equals(other.getExpiresAt()))
            && (this.getLogoutTime() == null ? other.getLogoutTime() == null : this.getLogoutTime().equals(other.getLogoutTime()))
            && (this.getLoginSource() == null ? other.getLoginSource() == null : this.getLoginSource().equals(other.getLoginSource()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
        result = prime * result + ((getToken() == null) ? 0 : getToken().hashCode());
        result = prime * result + ((getLoginTime() == null) ? 0 : getLoginTime().hashCode());
        result = prime * result + ((getExpiresAt() == null) ? 0 : getExpiresAt().hashCode());
        result = prime * result + ((getLogoutTime() == null) ? 0 : getLogoutTime().hashCode());
        result = prime * result + ((getLoginSource() == null) ? 0 : getLoginSource().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", userId=").append(userId);
        sb.append(", token=").append(token);
        sb.append(", loginTime=").append(loginTime);
        sb.append(", expiresAt=").append(expiresAt);
        sb.append(", logoutTime=").append(logoutTime);
        sb.append(", loginSource=").append(loginSource);
        sb.append("]");
        return sb.toString();
    }
}